package com.ymh.domain;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @author: 13590
 * @date: 2020/11/7 15:44
 * @description:
 */
@Data
@Accessors(chain = true)
public class UserDetailsDTO implements UserDetails {

  private Integer id;
  private Integer deptId;
  private String name;
  private String email;
  private String username;
  private String password;
  private Integer isAdmin;
  private Integer status;
  private Date createdTime;
  private Date updatedTime;
  private List<GrantedAuthority> authorities;

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    return authorities;
  }

  @Override
  public String getPassword() {
    return password;
  }

  @Override
  public String getUsername() {
    return username;
  }

  @Override
  public boolean isAccountNonExpired() {
    return true;
  }

  @Override
  public boolean isAccountNonLocked() {
    return true;
  }

  @Override
  public boolean isCredentialsNonExpired() {
    return true;
  }

  @Override
  public boolean isEnabled() {
    return status == 1;
  }


  @Data
  @AllArgsConstructor
  public static class CustomAuthority implements GrantedAuthority{
    private String permission;
    @Override
    public String getAuthority() {
      return permission;
    }
  }
}
